/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package myModel;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import java.sql.SQLException;

/**
 *
 * @author Abdullah Hamid
 */
public class userdao {
    
    protected String utype = null;

    public String ValidateUser(String cnumber, String pin) throws ClassNotFoundException, SQLException
    {

        ResultSet res;
        DAO d = new DAO();
        try{
            Connection conn= d.makeConn();
            Statement stat =  (Statement) conn.createStatement();
            String myQuery="Select * from users where CreditCard="+cnumber+" AND pin="+pin+"";
            System.out.println(myQuery);
            res = stat.executeQuery(myQuery);
            if(!res.next())
            {
                return "invalid";

            }
            else
            {
           // res.first();
                utype=res.getString(1);
                 return utype;
                
            }
        }
        catch(SQLException ex){
                System.err.println("in user verify" + ex.getMessage());
        }
        return utype;
    }
}
